﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HZ.DrugTrade.Web.Enterprise.InvoiceManage
{
    public partial class InvoicePayList :BasePage
    {
        IBLL.IBLL_Purchase ip = BLLFactory.Factory.BLL_Purchase();
        private static string hospitalId;
        protected void Page_Load(object sender, EventArgs e)
        {
            hospitalId = Request.QueryString["hospitalID"].ToString();
            if (string.IsNullOrEmpty(hospitalId))
            {
                HZ.Web.WebUtil.Alert("请先选择医疗机构！", this);
                HZ.Web.WebUtil.RedirectByScript("HistroyTradeRecord.aspx");
            }
            if (!IsPostBack)
            {
                BindBaseInfo();
                BindData();
            }
        }

        /// <summary>
        /// 获取医疗机构的基本信息
        /// </summary>
        private void BindBaseInfo()
        {
            //获取该医疗机构的结算情况
            int totalcount = 0;
            System.Data.DataTable dt = ip.GetHistroyTradeHospital(hospitalId, "", CurrentAccount.GetUser().Org.OrgID,1,0,out totalcount);
            lblActualAmount.Text = dt.Rows[0]["actualAmount"].ToString();
            lblHospitalName.Text = dt.Rows[0]["HospitalName"].ToString();
            lblOweAmount.Text = dt.Rows[0]["oweAmount"].ToString();
            lblPayAmount.Text = dt.Rows[0]["payAmount"].ToString();
        }

        /// <summary>
        /// 绑定该医疗机构的所有结算单
        /// </summary>
        private void BindData()
        {
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            HZ.DrugTrade.Model.Query.InvoicePay qryWhere = new HZ.DrugTrade.Model.Query.InvoicePay();
            //获取条件
            qryWhere.HospitalID = hospitalId;
            //qryWhere.InvoicePayNo = txtInvoicePayId.Text.Trim();
            qryWhere.InvoicePayName = txtInvoicePayName.Text.Trim();
            qryWhere.CompanyID_PS = CurrentAccount.GetUser().Org.OrgID;
            qryWhere.PayStatus = 1;
            qryWhere.SortFields = "InvoicePayTime DESC";
            int totalRecord = 0;
            //获取符合条件的数据
            IList<Model.View.InvoicePay> lstInvoicePay = new List<Model.View.InvoicePay>();
            lstInvoicePay = ip.GetTotalInvoicePayByWhere(qryWhere, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalRecord);
            gvwProcurementProjectList.DataSource = lstInvoicePay;
            gvwProcurementProjectList.AutoGenerateColumns = false;
            gvwProcurementProjectList.DataBind();
            AspNetPager1.RecordCount = totalRecord;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }
    }
}
